package com.esisa.IHM;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFrame;
import javax.swing.JPanel;

import com.esisa.beans.Etudiant;
import com.esisa.beans.ListeSCORM;
import com.esisa.listners.ChooseFile;
import com.esisa.listners.CopyPastListner;
import com.esisa.listners.Save;
import com.esisa.swing.ButtonPanel;
import com.esisa.swing.Form;

public class InterfaceModifierDocument extends JFrame{

	public InterfaceModifierDocument(final Etudiant d) {
		
		setTitle("Nouveau Document");
		setSize(400,700);
		final Form f=new Form(new String[]{"Nom","Prenom","Chemin","Age","Absence","Presence","Retard","Remarque"});
	    f.setText(0,d.getNom());
	    f.setText(1,d.getPrenom());
	    f.setText(2,d.getChemin());
	    f.setText(3,d.getAge());
	    f.setText(4,d.getAbsence());
	    f.setText(5,d.getPresence());
	    f.setText(6,d.getRetard());
	    f.setText(7,d.getRemarque());
	    
	    
		f.addMouseListener(new CopyPastListner());
		JPanel paneau=new JPanel();
		paneau.setLayout(new BorderLayout());
		paneau.add(f);
		ButtonPanel b=new ButtonPanel(new String[]{"Valider","Fermer"});
		
		b.addActionListner(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				dispose();
			}
		},"Fermer");
		b.addActionListner(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				
				Etudiant nouveaudoc= new Etudiant(f.getText(0),
						f.getText(1),
						f.getText(2),
						f.getText(3),
						f.getText(4),
						f.getText(5),
						f.getText(6),
						f.getText(7)
						);
				ListeSCORM document=new ListeSCORM();
				document.load("resources/doc.txt");
				document.modify(d.getChemin(),nouveaudoc);
				dispose();
				new ListerTousLesDocuments("modi");
			}
		},"Valider");
		
		paneau.add(b, "South");
		setContentPane(paneau);
		setVisible(true);
	}

}
